<template>
  <div class="app-container">
    <div class="zd3">
      <div class="zd3-title">
        <p>
          <span>产品名</span>
          <input v-model="proname" type="text" placeholder="请输入产品名" />
        </p>
        <p>
          <span>含量</span>
          <input v-model="hanliang" type="text" placeholder="请输入含量" />
        </p>
        <h3 @click="search">查询</h3>
        <h4 @click="resetList">重置</h4>
      </div>
      <div class="zd3-btm">
        <el-table :data="tableData" v-loading="loading" style="width: 100%;border-radius: 8px;">
          <el-table-column type="index" align="center" label="序号" width="80" />
					<el-table-column align="center" prop="nametitle" label="产品名" width="250" />
					<el-table-column align="center" prop="hanliang" label="含量" />
          <!-- <el-table-column align="center" prop="kg" label="毛重" /> -->
          <el-table-column align="center" prop="beizhu" label="备注" />
          <el-table-column align="center" prop="queren" label="确认使用">
            <template slot-scope="scope">
              <div class="orderStatus">
                <el-switch
                  v-model="scope.row.queren"
                  width="55"
                  active-value="1"
                  inactive-value="0"
                  active-text="正常"
                  inactive-text="停用"
                  @change=chang($event,scope.row)
                ></el-switch>
                <!-- <p
                  :class="scope.row.status == 0 ? 'blue' : 'green'"
                >{{scope.row.status == 0 ? '停止' : '正常'}}</p> -->
              </div>
            </template>
          </el-table-column>
          <el-table-column align="center" width="200" label="操作">
            <template slot-scope="scope">
              <el-button type="text" size="small" @click="look(scope.row)">查看</el-button>
              <el-button type="text" size="small" @click="write(scope.row)">修改</el-button>
              <el-popconfirm
                placement="top"
                hideIcon
                title="是否要删除此行？"
                @onConfirm="deleteRow(scope.row)"
              >
                <el-button type="text" size="small" slot="reference">删除</el-button>
              </el-popconfirm>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
          background
          :page-size="50"
          layout="prev, pager, next"
          :total="total"
          align="right"
          @prev-click="goPrev"
          @next-click="goNext"
          @current-change="goPage"
        />
      </div>
    </div>
  </div>
</template>

<script>
import { getEwmMuban, deleteEwmMuban,updateEwmMuban } from "@/api/ewmApi";
export default {
  name: 'Moban',
  data() {
    return {
      proname: "",
      hanliang: "",
      total: 1,
      pages: 1,
      tableData: [],
      dialogVisible: false,
      tempData: "",
      tempIndex: -1,
      loading: true
    };
  },
  mounted() {
    this.search();
  },
  methods: {
    changeValue3(value) {},
    write(item) {
      console.log(item);
      this.$router.push({
        name: "Wirtemoban",
        params: {
          options: JSON.stringify(item)
        }
      });
    },
    search() {
      if(this.proname || this.hanliang){
        this.pages = 1
      }
      const param = {
        nametitle: this.proname ? this.proname : null,
        hanliang: this.hanliang ? this.hanliang : null,
        currentPage: this.pages
      };
      getEwmMuban(param).then(res => {
        console.log(res);
        // res.data.records.map((item,index) => {
        //   console.log(index)
        //   if(index % 2 == 0){
        //     console.log(1)
        //     item.queren = '1'
        //   }else{
        //     console.log(0)
        //     item.queren = '0'
        //   }
        //   return item
        // })
        this.tableData = res.data.records;
        this.total = res.data.total
        this.loading = false;
      });
    },
    resetList() {
      this.proname = ""
      this.hanliang = ''
    },
    look(item) {
      this.$router.push({
        name: "Lookmoban",
        params: {
          options: JSON.stringify(item)
        }
      });
    },
    // 修改停用状态
    chang(even,row){
      console.log(even)
      console.log(row)
      updateEwmMuban({queren: even,id: row.id}).then(res => {
				console.log(res)
				this.$message({
					message: res.message,
					type: "success"
        })
        this.search();
			})
    },
    deleteRow(item) {
      console.log("删除");
      deleteEwmMuban(item.id).then(res => {
        console.log(res);
        this.$message({
          message: res.message,
          type: "success"
        });
        this.search();
      });
    },
    goPrev(page) {
      this.loading = true
      this.pages--
      this.search()
      console.log(page);
    },
    goNext(page) {
      this.loading = true
      console.log(page);
      this.pages++
      this.search()
    },
    goPage(page){
      this.loading = true
      this.pages = page
      this.search()
    }
  }
};
</script>

<style lang="scss" scoped>
/deep/.el-button--primary {
  color: #fff;
  background-color: #18a05e !important;
  border-color: #18a05e !important;
}
/deep/.el-button--primary:hover,
.el-button--primary:focus {
  background: #18a05e !important;
  border-color: #18a05e !important;
  color: #fff !important;
}
/deep/.el-button:hover,
.el-button:focus {
  color: #18a05e;
  background-color: transparent;
}
/deep/.el-button--primary {
  color: #fff;
  background-color: #18a05e;
  border-color: #18a05e;
}
/deep/.el-button--text {
  color: #00c666 !important;
}
.app-container {
  padding: 10px;
}
.proimg {
  width: 30px;
  height: 30px;
}
.inps {
  width: 100%;
  height: 32px;
  line-height: 32px;
  padding-left: 10px;
  background: none;
  border: none;
  color: #333;
}
.orderStatus {
  display: flex;
  justify-content: center;
  align-items: center;
  > p {
    padding: 0px 5px;
    color: #fff;
    border-radius: 2px;
    font-size: 14px;
    // margin: 0 10px 0 0;
  }
  .blue {
    background: #3a87ad;
  }
  .green {
    background: #18a05e;
  }
  .yellow {
    background: #ff7a0e;
  }
  .red {
    background: #c60000;
  }
}
.inps-active {
  width: 100%;
  height: 32px;
  line-height: 32px;
  padding-left: 10px;
  // background:#ccc;
  border: none;
  color: #333;
}
.zd3-title {
  height: 80px;
  display: flex;
  align-items: center;
  padding: 0 20px;
  position: relative;
  background: #ffffff;
  border-radius: 8px;
  border: 1px solid rgba(0, 0, 0, 0.1);

  > p {
    font-size: 14px;
    color: #333;
    margin-right: 20px;

    > span {
      padding-right: 20px;
    }

    > input {
      width: 150px;
      height: 32px;
      // background: #ccc;
      border-radius: 3px;
      border: 1px solid #ccc;
      padding-left: 10px;
      color: #333;
    }
  }

  > h3 {
    // width: 64px;
    height: 32px;
    background: #18a05e;
    border-radius: 3px;
    margin: 0 30px 0 0;
    padding: 0 15px;
    color: #fff;
    font-size: 14px;
    line-height: 32px;
    font-weight: 100;
    text-align: center;
    cursor: pointer;
  }

  > h4 {
    padding: 0 15px;
    height: 32px;
    border-radius: 3px;
    border: 1px solid rgba(0, 0, 0, 0.1);
    color: #333;
    font-size: 14px;
    line-height: 32px;
    font-weight: 100;
    text-align: center;
    cursor: pointer;
  }
}
/deep/.el-pagination.is-background .el-pager li:not(.disabled).active {
  background-color: #18a05e !important;
  color: #fff;
}
/deep/.btn-prev:after {
  content: "上一页";
}
/deep/.btn-next:before {
  content: "下一页";
}
/deep/.btn-prev,
/deep/.btn-next {
  width: 65px !important;
	display: inline-flex !important;
	align-items: center !important;
	justify-content: center !important;
}
.zd3-btm {
  background: rgba(255, 255, 255, 1);
  border-radius: 8px;
  border: 1px solid rgba(0, 0, 0, 0.1);
  margin-top: 10px;
  overflow: hidden;
  /deep/.el-switch__label--left {
    position: relative;
    left: 55px;
    color: #fff;
    z-index: -1111;
  }
  /deep/.el-switch__label--right {
    position: relative;
    right: 55px;
    color: #fff;
    z-index: -1111;
  }
  /deep/.el-switch__label.is-active {
    z-index: 1111;
    color: #fff;
  }
  /deep/.el-switch__label * {
    line-height: 1;
    font-size: 12px;
    display: inline-block;
  }
  /deep/.el-switch__label--left {
    position: relative;
    left: 55px;
    color: #fff;
    z-index: -1111;
  }
  /deep/.el-switch__label--right {
    position: relative;
    right: 55px;
    color: #fff;
    z-index: -1111;
  }
  /deep/.el-switch__label--right.is-active {
    z-index: 1111;
    color: #fff !important;
  }
  /deep/.el-switch__label--left.is-active {
    z-index: 1111;
    color: #9c9c9c !important;
  }
  &-title {
    display: flex;
    align-items: center;
    height: 70px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    background: #ffffff;
    > p {
      text-align: center;
      font-size: 16px;
      color: #333;
    }
  }
  .el-pagination {
		white-space: nowrap;
		padding: 15px 5px;
		color: #303133;
		font-weight: bold;
	}
  .addDate {
    margin: 20px 32px 10px 32px;
    height: 32px;
    border-radius: 3px;
    text-align: center;
    line-height: 32px;
    font-size: 14px;
    color: #333;
    cursor: pointer;
    border: 1px dashed rgba(0, 0, 0, 0.25);
  }
  .el-button--text {
    margin: 0 15px;
  }
}
.change {
  display: flex;
  flex-wrap: wrap;
  > p {
    width: 50%;
    font-size: 14px;
    display: flex;
    align-items: center;
    color: #333;
    /deep/.el-input__inner {
      width: inherit;
      background: none;
      height: 32px;
      // line-height: 32px;
      color: #333;
      border: 1px solid rgba(0, 0, 0, 0.1);
      padding: 0 25px;
    }
    /deep/.el-input__icon {
      line-height: 32px;
    }
    .userselect {
      // max-width: 250px;
      flex: 1;
    }

    > span {
      display: block;
      width: 120px;
      text-align: right;
      padding-right: 15px;
    }
    > input {
      width: inherit;
      flex: 1;
      height: 32px;
      border-radius: 3px;
      border: 1px solid rgba(0, 0, 0, 0.1);
      padding-left: 10px;
      color: #333;
    }
  }
}
</style>
